from flask_restful import Resource

from restful.api__.session import login_required_current_user_generate, \
    pid_required_target_post_generate
from restful.model.query import QueryMultipleInstances
from restful.model.tables import Like
from restful.response import ResponseSuccess


class PostAllLikes(Resource):
    @login_required_current_user_generate
    @pid_required_target_post_generate
    def get(self,target_post,current_user):
        likes = QueryMultipleInstances(Like,{'pid':target_post.id})
        return ResponseSuccess(data=[{
                'uid':i.uid,
                'time':i.time
            } for i in likes]
        )